//#include <iostream>
//using namespace std;
//
//
//
//int main()
//{
//	cout << 202420242024 * 12;
//	return 0;
//}


#include <iostream>
using namespace std;

typedef long long ll;
const int N = 1e5 + 10;
int a[N];
int n, cnt;

int gcd(int x, int y)
{
	return y == 0 ? x : gcd(y, x % y);
}
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]), cnt += a[i] == 1 ? 1 : 0;
	if(cnt) {
		cout << n - cnt;
		return 0;
	}
	int ans = 1e9;
	for(int i = 1; i < n; i++)
	{
		int x = a[i], sum = 0;
		for(int j = i + 1; j <= n; j++)
		{
			sum++;
			x = gcd(x, a[j]);
			if(j - i > ans) break;
			if(x == 1)
			{
				ans = min(ans, sum);
				break;
			}
		}	
	}
	if(ans == 1e9) cout << -1;
	else cout << n - 1 + ans;
	return 0;
}
